// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   BasePRNG.java

package gnu.crypto.prng;

import java.util.Map;

// Referenced classes of package gnu.crypto.prng:
//            IRandom, LimitReachedException

public abstract class BasePRNG
    implements IRandom
{

    protected BasePRNG(String name)
    {
        this.name = name;
        initialised = false;
        buffer = new byte[0];
    }

    public String name()
    {
        return name;
    }

    public void init(Map attributes)
    {
        setup(attributes);
        ndx = 0;
        initialised = true;
    }

    public byte nextByte()
        throws IllegalStateException, LimitReachedException
    {
        if(!initialised)
            throw new IllegalStateException();
        else
            return nextByteInternal();
    }

    public void nextBytes(byte out[], int offset, int length)
        throws IllegalStateException, LimitReachedException
    {
        if(out == null)
            return;
        if(!initialised)
            throw new IllegalStateException();
        if(offset < 0 || offset >= out.length || length < 1)
            return;
        int limit = offset + length <= out.length ? length : out.length - offset;
        for(int i = 0; i < limit; i++)
            out[offset++] = nextByteInternal();

    }

    public boolean isInitialised()
    {
        return initialised;
    }

    private byte nextByteInternal()
        throws LimitReachedException
    {
        if(ndx >= buffer.length)
        {
            fillBlock();
            ndx = 0;
        }
        return buffer[ndx++];
    }

    public abstract Object clone();

    public abstract void setup(Map map);

    public abstract void fillBlock()
        throws LimitReachedException;

    protected String name;
    protected boolean initialised;
    protected byte buffer[];
    protected int ndx;
}
